use UMAS0011_OUTPUT.DTA, clear

set more off
drop zipcode
ren lookupzip zipcode
sort zipcode

merge zipcode using combinedzipcodes
drop if _m==2
drop _m

gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>10

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"

recode pid3 4/5=3

gen age=2013-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

recode race 5/9=., gen(racecat)
replace racecat=3 if hispanic==1

recode educ 1/2=1 3=2 4/5=3 6=4, gen(educcat)
label define educcat 1 "HS or less" 2 "Some college" 3 "College degree" 4 "Postgraduate"
label values educcat educcat


svyset [pw=weight]

*** First you need to recode dependent variables to be binaries.
* If you have more than two categories, you can produce more than one binary
* But can collapse lot of stuff (i.e. Q17 can be % supportive)

recode Q16 2=0, gen(jobs)
recode Q9c 2/3=0, gen(righttrack)
recode Q9c 2=1 1=0 3=0, gen(wrongtrack)
recode Q17 2=1 3/5=0, gen(supportbusiness)
recode Q17 3/4=1 1/2=0 5=0, gen(unsupportbusiness)
recode Q18 2=1 3/6=0, gen(transitgoodexcellent)
recode Q18 1/2=0 3/5=1 6=0, gen(transitfairpoor)

recode Q19 2=1 3/5=0, gen(transiteasy)
recode Q19 1/2=0 3/4=1 5=0, gen(transitdifficult)

recode Q20 2=1 3/5=0, gen(cleanalwaysusually)
recode Q20 1/2=0 3/4=1 5=0, gen(cleanseldomnever)

recode Q21a 2=1 3/4=0, gen(safeday)
recode Q21b 2=1 3/4=0, gen(safenight)

recode Q22 2=1 3/5=0, gen(racerelationsbetter)

recode Q23c 2=1 3/5=0, gen(meninoapprove)
recode Q23c 1/2=0 3/4=1 5=0, gen(meninodisapprove)

recode Q23d 2=1 3/5=0, gen(councilapprove)
recode Q23d 1/2=0 3/4=1 5=0, gen(councildisapprove)

recode Q24 2=0, gen(cityrunwell)
recode Q26 2=0, gen(newdirection)

recode Q28 2=1 3/4=0, gen(attentionalotsome)

*Mayoral Candidates

*Top 5 - Boston Voters
*connolly
*arroyo
*clemons
*walczak
*barros
recode Q32a_8 1=1 2/5=0, gen(bos_connolly)
recode Q32a_9 1=1 2/5=0, gen(bos_arroyo)
recode Q32a_1 1=1 2/5=0, gen(bos_clemons)
recode Q32a_2 1=1 2/5=0, gen(bos_walczak)
recode Q32a_12 1=1 2/5=0, gen(bos_barros)

*Top 5 - Non-Boston Voters
*conley
*connolly
*walsh
*ross
*clemons
recode Q32b_11 1=1 2/5=0, gen(nonbos_conley)
recode Q32b_8 1=1 2/5=0, gen(nonbos_connolly)
recode Q32b_7 1=1 2/5=0, gen(nonbos_walsh)
recode Q32b_6 1=1 2/5=0, gen(nonbos_ross)
recode Q32b_1 1=1 2/5=0, gen(nonbos_clemons)


*Who will win?
recode Q33 1=1 2/12=0, gen(clemons)
recode Q33 2=1 1=0 3/12=0, gen(walczak)
recode Q33 3=1 1/2=0 4/12=0, gen(yancey)
recode Q33 4=1 1/3=0 5/12=0, gen(consalvo)
recode Q33 5=1 1/4=0 6/12=0, gen(richie)
recode Q33 6=1 1/5=0 7/12=0, gen(ross)
recode Q33 7=1 1/6=0 8/12=0, gen(walsh)
recode Q33 8=1 1/7=0 9/12=0, gen(connolly)
recode Q33 9=1 1/8=0 10/12=0, gen(arroyo)
recode Q33 10=1 1/9=0 11/12=0, gen(wyatt)
recode Q33 11=1 1/10=0 12=0, gen(conley)
recode Q33 12=1 1/11=0, gen(barros)

*MOST IMPROVED ISSUE
recode Q25q_1 1=1 2=0, gen(most_promotecity)
recode Q25p_1 1=1 2=0, gen(most_tourist)
recode Q25o_1 1=1 2=0, gen(most_biz)
recode Q25m_1 1=1 2=0, gen(most_parknrec)
recode Q25d_1 1=1 2=0, gen(most_crime)

*LEAST IMPROVED ISSUE
recode Q25k_2 1=1 2=0, gen(least_tax)
recode Q25c_2 1=1 2=0, gen(least_parking)
recode Q25b_2 1=1 2=0, gen(least_traffic)
recode Q25a_2 1=1 2=0, gen(least_masstransit)
recode Q25g_2 1=1 2=0, gen(least_housing)

*** Recode categories of the independent variables to what you want in columns

recode Q1 2=1 3/6=2, gen(inboston)
label define timeinboston 1 "Weekly" 2 "Less than Weekly"
label values inboston timeinboston

*** This commmand must be downloaded from Stata, but it produces the entire set of crosstabs at once

tablemat jobs-attention [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean) 

tablemat bos_connolly bos_arroyo bos_clemons bos_walczak bos_barros [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean) 

tablemat nonbos_conley nonbos_connolly nonbos_walsh nonbos_ross nonbos_clemons [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean) 

tablemat connolly conley arroyo walsh consalvo [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean)

tablemat most_promotecity most_tourist most_biz most_crime most_parknrec [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean)

tablemat least_parking least_tax least_traffic least_masstransit least_housing [aw=weight], by(area inboston gender agecat racecat incomecat educcat pid3 ideo3) st(mean)
*bos_connolly bos_arroyo bos_clemons bos_walczak bos_barros nonbos_conley nonbos_connolly nonbos_walsh nonbos_ross nonbos_clemons connolly wyatt conley walsh arroyo most_promotecity most_tourist most_biz most_parknrec most_crime least_tax least_parking least_traffic least_masstransit least_housing
